<template>
  <div style="width:100%;height:100%">
    <v-chart :options="option" :initOptions="initOptions" :theme="theme" autoresize />
  </div>
</template>
<script>

export default {
  name: 'chart',
  props: ['index'],
  mounted () {
  },
  data () {
    return {
      initOptions: { renderer: 'canvas' },
      theme: 'default'
    }
  },
  methods: {
  },
  computed: {
    insideSlideArray () {
      return this.$store.state.layout[this.$store.state.activeArrayIndex].SlideContent
    },
    insideArrayIndex () {
      return this.insideSlideArray.indexOf(this.insideSlideArray.filter((currentValue) => {
        return currentValue.i === this.index
      })[0])
    },
    getDetail () {
      return this.$store.state.layout[this.$store.state.activeArrayIndex].SlideContent[this.insideArrayIndex].itemContent.detail
    },
    getSeries () {
      var series = []
      series.push({
        name: this.getDetail.sheetData[0][1],
        type: 'bar',
        xAxisIndex: 1,
        yAxisIndex: 1,
        encode: {
          x: 1,
          y: 0
        },
        ...this.getDetail.simpleBar,
        backgroundStyle: {
            color: this.getDetail.simpleBar.backgroundStyle[this.getDetail.simpleBar.backgroundStyle.option]
        }
      })
      series.push({
        name: this.getDetail.sheetData[0][2],
        type: 'bar',
        xAxisIndex: 2,
        yAxisIndex: 2,
        encode: {
          x: 2,
          y: 0
        },
        ...this.getDetail.simpleBar,
        backgroundStyle: {
            color: this.getDetail.simpleBar.backgroundStyle[this.getDetail.simpleBar.backgroundStyle.option]
        }
      })
      return series
    },
    getLabel () {
        var label = []
        for (let i = 1, nr = this.getDetail.nr; i < nr; i++) {
        label.push({
          value: this.getDetail.sheetData[i][0],
          textStyle: {
              align: 'center'
          }
        })
      }
      return label
    },
    option () {
      return {
        baseOption: {
          animation: this.getDetail.animation,
          timeline: {
            data: this.getDetail.sheetData[0].slice(1),
            ...this.getDetail.timeline,
            playInterval: 8000
          },
          itemStyle: {
            ...this.getDetail.itemStyle
          },
          title: this.getDetail.title,
          dataset: {
            source: this.getDetail.sheetData,
            sourceHeader: true
          },

          grid: this.getDetail.grid,
          xAxis: this.getDetail.xAxis,
          yAxis: {
            ...this.getDetail.yAxis,
            axisLabel: {
              show: false
            }
          },
          tooltip: {},
          backgroundColor: this.getDetail.backgroundColor[this.getDetail.backgroundColor.option]
        },
        options: this.getOptions
      }
    }
  }
}
</script>
<style scoped>
  .echarts {
    width: 100%;
    height: 100%;
  }
</style>
